//
//  CellVideoView.m
//  Budejie
//
//  Created by 远成物流 on 2017/5/16.
//  Copyright © 2017年 陈梦佳. All rights reserved.
//

#import "CellVideoView.h"
#import "ShowBigPictureController.h"
#import "UIImageView+Download.h"

@interface CellVideoView ()
@property (weak, nonatomic) IBOutlet UIImageView *placeholderView;
@property (weak, nonatomic) IBOutlet UIImageView *videoImage;
@property (weak, nonatomic) IBOutlet UIButton *playButton;
@property (weak, nonatomic) IBOutlet UILabel *playCount;
@property (weak, nonatomic) IBOutlet UILabel *videoTime;

@end

@implementation CellVideoView

-(void)awakeFromNib{
    
    [super awakeFromNib];
    
    self.autoresizingMask = UIViewAutoresizingNone;
    
    self.videoImage.userInteractionEnabled = YES;
//    [self.videoImage addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(showBigPicture)]];
}

- (IBAction)playButtonAction:(id)sender {
    
    if (self.playVideo) {
        self.playVideo((UIButton *)sender);
    }
    
}

//查看大图
-(void)showBigPicture{
    ShowBigPictureController *showBigPicture = Alloc(ShowBigPictureController);
    showBigPicture.topic = self.topic;
    [self.window.rootViewController presentViewController:showBigPicture animated:YES completion:nil];
}

-(void)setTopic:(EssenceTopic *)topic{
    
    _topic = topic;
    
    //播放次数
    if (topic.playcount >= 10000) {
        self.playCount.text = [NSString stringWithFormat:@"%.1f万播放",topic.playcount / 10000.0];
    }else{
        //格式符z和整数转换说明符一起使用，表示对应数字是一个size_t值。属于C99
        self.playCount.text = [NSString stringWithFormat:@"%zd播放",topic.playcount];
    }
    
    //时长
    self.videoTime.text = [NSString stringWithFormat:@"%02zd:%02zd",topic.videotime/60,topic.videotime%60];
    
    //图片
    self.placeholderView.hidden = NO;
    [self.videoImage setOriginalImage:topic.image1 thumbnailImage:topic.image0 placeholderImage:nil completed:^(UIImage * _Nullable image, NSError * _Nullable error, SDImageCacheType cacheType, NSURL * _Nullable imageURL) {
        if (!image) {
            return ;
        }
        
        self.placeholderView.hidden = YES;
    }];
}

@end
